// subpages0/giftCard/cardhome/cardhome.js
var app = getApp();
Page({
  data: {

  },
  onLoad: function (e) {
    var that = this;
    if (e && e.title) {
      app.setNavtitle(e.title);
    } else {
      app.setNavtitle('充值卡');
    }
    if (e && e.id) {
      that.setData({
        id: e.id
      })
    }
    if (!app.globalData.plumSession) {
      app.wechatSq(that);
    } else {
      that.requestCarddetail();
    }
  },
  onShow: function () {

  },
  onPullDownRefresh: function () {
    var that = this;
    that.requestCarddetail();
  },
  requestCarddetail: function () {
    var that = this;
    var data = {
      map: 'applet_giftcard_card_detail',
      id: that.data.id
    }
    console.log(data);
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.requestUrl,
      data: data,
      success: function (res) {
        console.log(res.data);
        if (res.data.ec == 200) {
          that.setData({
            cardDetail: res.data.data
          })
        } else {
          app.errorTip(that, res.data.em, 2000);
        }
      },
      complete: function () {
        wx.hideLoading();
        wx.stopPullDownRefresh();
      }
    });
  },
  // 卡详情弹窗
  showDetailmodal:function(){
    var that = this;
    that.setData({
      isShowDetail:true
    })
  },
  hideDetailmodal: function () {
    var that = this;
    that.setData({
      isShowDetail: false
    })
  },
  // 购物车弹窗
  showCartmodal: function () {
    var that = this;
    that.setData({
      isShowCart: !that.data.isShowCart
    })
  },
  hideCartmodal: function () {
    var that = this;
    that.setData({
      isShowCart: false
    })
  },
  // 阻止弹窗下面页面滑动
  stopProp:function(e){
    console.log(e);
  },
  //核销二维码显示
  codeModelShow: function () {
    var that = this;
    that.setData({
      codeShow: true
    })
  },
  //核销二维码弹窗关闭
  closeCodeModel: function () {
    var that = this;
    that.setData({
      codeShow: false
    })
  },
  toczcardxfRecord:function(){
    var that = this;
    wx.navigateTo({
      url: '/subpages0/giftCard/czcardxfRecord/czcardxfRecord?id='+that.data.id,
    })
  },
  toczcardUseintro: function () {
    var that = this;
    var cardDetail = that.data.cardDetail;
    wx.setStorage({
      key: 'cardUseintro',
      data: cardDetail.rule,
      success:function(){
        wx.navigateTo({
          url: '/subpages0/giftCard/czcardUseintro/czcardUseintro',
        })
      }
    })
    
  }
})